import http from "../utils/request"
import {PageRequestType, ResponseType, PageResponseType} from "../types/Response";
import {AxiosResponse} from "axios";

const apiPrefix:string = "/admin";

export interface AdminType {
    // 管理员id
    id?:string|null|undefined
    // 管理员用户名
    username?:string|null|undefined
    // 密码
    password?:string|null|undefined
    // 等级(1超级管理员,,2普通管理员)
    level?:number|null|undefined
    // 账号状态(0封禁,1正常)
    state?:number|null|undefined
    // 手机号
    phone?:string|null|undefined
    // 邮箱
    mail?:string|null|undefined
    // 年龄
    age?:number|null|undefined
    // 1男2女
    gender?:number|null|undefined
    // 头像
    photo?:string|null|undefined
}

export interface AdminPageSearchType extends PageRequestType, AdminType {

}


export async function addAdmin(data: AdminType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'post'
    })
}

export async function deleteAdminById(id: string): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'delete'
    })
}

export async function deleteAdminByIds(ids: string[]): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        params: {
            ids
        },
        url: apiPrefix+'/batch',
        method: 'delete'
    })
}


export async function searchAdminById(id: string): Promise<AxiosResponse<ResponseType<AdminType>>> {
    return await http.request({
        params: {
            id
        },
        url: apiPrefix+'/id',
        method: 'get'
    })
}

export async function searchAdmin(params: AdminType): Promise<AxiosResponse<ResponseType<AdminType[]>>> {
    return await http.request({
        params: params,
        url: apiPrefix,
        method: 'get'
    })
}

export async function searchAdminByPage(params: AdminPageSearchType): Promise<AxiosResponse<ResponseType<PageResponseType<AdminType>>>> {
    return await http.request({
        params: params,
        url: apiPrefix+'/page',
        method: 'get'
    })
}


export async function updateAdminById(data: AdminType): Promise<AxiosResponse<ResponseType<null>>> {
    return await http.request({
        data: data,
        url: apiPrefix,
        method: 'put'
    })
}
